﻿<cfsilent>
	<cfscript>
		
		sql = "	SELECT
					b.b_id,b.b_name
				FROM
					t_building b
				WHERE
					b.b_id = :buildingId ";
					
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "buildingId", value =  event.getArg("BID"), cfsqltype = "cf_sql_char");
		rs_buildEntity = queryObj.execute( sql = sql ).getResult();
		
		sql = "	SELECT
					c.cr_id,
					c.cr_usage,
					c.classroom,
					ct.cr_type_name,
					c.cr_floor,
					c.sits,
					c.sits_course,
					c.sits_exam
				FROM
					t_classroom c
					INNER JOIN t_classroom_type ct ON ct.cr_type = c.cr_type
				WHERE
					c.b_id = :buildingId 
				ORDER BY
					c.cr_floor ASC,c.classroom ASC";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "buildingId", value =  rs_buildEntity.b_id, cfsqltype = "cf_sql_char");
		rs_clsroom = queryObj.execute( sql = sql ).getResult();

		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		usageAdvice = getProperty("serviceFactory").getBean("classroomUsageAdvice");
		
		temFile = GetTempDirectory() & createUUID() & ".xls";
		downFile = URLEncodedFormat(rs_buildEntity.b_name & "教学场地信息", "utf-8");
		
		excel = getProperty("serviceFactory").getBean("spreadSheetObject");
		
		/* 创建工作簿 */
		spreadsheetObj = excel.SpreadSheetNew("教学场地", false);
		
		/* 添加表头 */
		excel.SpreadsheetAddrow(spreadsheetObj, "教学场地,教室类别,所在楼层,座位数,排课容量,考试容量,是否可用,排课,考试,日常借用,自习");
		
		row = 1;
		
		//for ( entity in clsroomArray ) {
		for(a = 1; a lte rs_clsroom.recordCount; a++){
			
			usageAdvice.parseUsage( rs_clsroom['cr_usage'][a] );
			
			row++;
			
			/* 构建教室信息 */
			rowData = rs_clsroom['classroom'][a]
						& ","
						& rs_clsroom['cr_type_name'][a]
						& ","
						& dictAdvice.getFloorString(rs_clsroom['cr_floor'][a])
						& ","
						& rs_clsroom['sits'][a]
						& ","
						& rs_clsroom['sits_course'][a]
						& ","
						& rs_clsroom['sits_exam'][a]
						& ","
						& usageAdvice.getRunning()
						& ","
						& usageAdvice.getForCourse()
						& ","
						& usageAdvice.getForExam()
						& ","
						& usageAdvice.getForBorrow()
						& ","
						& usageAdvice.getForStudy();
				
			/* 写入教室信息 */
			excel.SpreadsheetAddrow(spreadsheetObj, rowData);
		}
		
		excel.SpreadSheetWrite(spreadsheetObj, temFile, true);

	</cfscript>
	
	<cfheader name="Content-Disposition" value="attachment; filename=#downFile#.xls" />
	<cfcontent file="#temFile#" reset="yes" type="application/msexcel" deletefile="yes" />	

</cfsilent>